<template>
  <div>
    <van-nav-bar
      fixed
      :title="`${currentComment.reply_count}条回复`"
      left-arrow
      @click-left="$emit('close')"
  >
    <van-icon name="cross" slot="left"/>
  </van-nav-bar>
    <commentItem :comment="currentComment"></commentItem>
    <van-cell title="全部回复"/>
    <commentList :type="'c'" :artID="currentComment.com_id" :list="list">
    </commentList>
    <!-- 发布评论 -->
    <div class="reply-comment">
      <van-button type="primary" round class="btn" @click="popupIsSHOW = true">写评论</van-button>
    </div>
    <!-- 回复评论 弹层 -->
    <van-popup v-model="popupIsSHOW" position="bottom">
      <addComment :list="list" @addComment="addComment" :artID="currentComment.com_id"></addComment>
    </van-popup>
  </div>
</template>

<script>
import commentItem from '@/components/commentItem'
import commentList from '@/views/article/components/commentList'
import addComment from '@/views/article/components/addComment'
export default {
  data () {
    return {
      popupIsSHOW: false,
      list: []
    }
  },
  props: {
    currentComment: {
      type: Object,
      required: true
    }
  },
  components: {
    commentItem,
    commentList,
    addComment
  },
  methods: {
    addComment (data) {
      console.log(data)
      this.popupIsSHOW = false
      // 将最新评论放在最前边显示
      this.list.unshift(data)
    }
  }
}
</script>

<style lang="less" scoped>
.reply-comment {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 88px;
  background-color: springgreen;
  .btn {
    height: 60px;
    width: 60%;
    background-color: springgreen;
  }
}
</style>
